"""
提交页面方法
"""
from common.base import Base, get_driver
from selenium.webdriver.common.by import By


class SubmitOrder(Base):
    # 邮局平邮
    def click_post(self):
        self.click((By.XPATH, "//input[@value='6']"))

    # 余额付款
    def click_balance(self):
        self.click((By.XPATH, "//input[@name='payment' and @value='1']"))

    # 银行转账
    def click_bank_transfer(self):
        self.click((By.XPATH, "//input[@name='payment' and @value='2']"))

    # 精品包装
    def click_boutique(self):
        self.click((By.XPATH, '//input[@name="pack" and @value="1"]'))

    # 要祝福卡
    def click_wish(self):
        self.click((By.XPATH, "//input[@name='card' and @value='1']"))

    # 点击发票
    def click_bill(self):
        self.click((By.ID, "ECS_NEEDINV"))

    # 发票类型
    def click_bill_type(self):
        self.click((By.XPATH, "//option[@value='2']"))

    # 订单附言
    def send_keys_remark(self, remark):
        self.send_keys((By.NAME, "postscript"), remark)

    # 点击提交订单
    def click_submit(self):
        self.click((By.XPATH, '//input[@src]'))


if __name__ == '__main__':
    # 创建浏览器驱动
    driver = get_driver()
    submit_order = SubmitOrder(driver)
    # 访问目标网址
    submit_order.get('http://localhost:8080/ecshop/flow.php?step=checkout')
    submit_order.click_post()
    submit_order.click_balance()
    submit_order.click_bank_transfer()
    submit_order.click_boutique()
    submit_order.click_wish()
    submit_order.click_bill()
    submit_order.click_bill_type()
    submit_order.send_keys_remark("尽快发货")
    submit_order.click_submit()
    submit_order.quit(2)
